Ext.define('Service.module.view.ModuleActionGrid', {
    extend: 'Ext.grid.Panel',
    
    id : 'Service_module_view_ModuleActionGrid',
    alias : 'widget.Service_module_view_ModuleActionGrid',
    style : {
    	border:'none'
    },
    forceFit : true,
    moduleId : -1,
    
    loadData : function(params){
    	var me = this;
    	me.moduleId = params['moduleId'];
    	me.setTitle('【'+params['moduleText']+'】模块Action列表（双击记录直接修改）');
    	me.getStore().addRequestParams(params).load();
    },
    
    initComponent: function() {
        var me = this;
        me.rowEditor = new Ext.grid.plugin.RowEditing({
        	ptype : 'Service_module_view_ActionRowEditing',
        	pluginId : 'Service_module_view_ActionRowEditing',
			clicksToMoveEditor: 1,
			autoCancel: false
		});
		me.rowEditor.on({
			canceledit : function(editor,e,opts){
				if(this.editType == 'add'){
					e.store.remove(e.record);
				}
			}
		});
        Ext.apply(me,{
        	title : 'Action列表',
        	store : new Service.module.store.ActionDataListStore(),
        	columns: [
		        {
		            xtype: 'gridcolumn',
		            hideable: false,
		            text: 'Action名称',
		            dataIndex : 'actionName',
		            editor : {
		            	allowBlank : false,
		            	blankText : 'Action Name不能为空',
		            	emptyText : 'NewAction',
		            	vtype : 'alpha'
		            }
		        },
		        {
		            xtype: 'gridcolumn',
		            hideable: false,
		            text: '展示名称',
		            dataIndex : 'actionText',
		            editor : {
		            	allowBlank : false,
		            	blankText : '展示名称不能为空',
		            	emptyText : '新的Action'
		            }
		        },
		        {
		            xtype: 'datecolumn',
		            text: '创建时间',
		            dataIndex : 'createTime',
		            format : 'Y-m-d'
		        },
		        {
		            xtype: 'datecolumn',
		            text: '修改时间',
		            dataIndex : 'updateTime',
		            format : 'Y-m-d'
		        },
		        {
		            xtype: 'actioncolumn',
		            width:30,
		            items: [
		                {
		                	iconCls : 'action-action-delete',
		                	tooltip : '删除',
							handler : function(grid,row,col,icon,e){
								Ext.MessageBox.show({
						    		title : '操作提示',
						    		msg : 'Action将被删除，确认操作？',
						    		width : 200,
						    		buttons : Ext.MessageBox.OKCANCEL,
						    		icon : Ext.MessageBox.WARNING,
						    		fn : function(buttonId){
						    			var me=this;
								    	if(buttonId == 'ok'){
								    		me.rowEditor.editType = 'del';
								    		var store = grid.getStore();
								    		store.removeAt(row);
								    	}
						    		},
						    		scope : me
						    	});
							}
		                }
		            ]
		        }
		    ],
		    viewConfig: {

    		},
    		dockedItems: [
                {
                    xtype: 'toolbar',
                    dock: 'top',
                    items: [
                        {
                            xtype: 'button',
                            text: '添加Action',
                            iconCls : 'add-module-action',
                            handler : function(){
                            	me.rowEditor.cancelEdit();
								me.rowEditor.editType = 'add';
				                var r = new Service.module.model.ActionModel({
				                	createTime : new Date(),
				                	updateTime : new Date()
				                });
				                me.getStore().insert(0, r);
				                me.rowEditor.startEdit(0, 0);
                            }
                        },
                        {
                            xtype: 'button',
                            text: '保存修改',
                            iconCls : 'save-module-action',
                            module: 'module',
                            action: 'saveActions',
                            plugins : [
                            	SessionPermissionPlugin
                            ]
                        }
                    ]
                }
            ],
    		plugins : [
    			me.rowEditor
    		]
        });
        me.callParent(arguments);
    }
});